﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Temp_20190707_AForm.Dock
{
    public class DockSplitControl : System.Windows.Forms.SplitContainer
    {
        public DockSplitControl()
        {
            this.ParentChanged += DockSplitControlParentChanged;
            this.Panel1.ControlAdded += DockSplitControlPanelControlAdded;
        }

        private void DockSplitControlParentChanged(object sender, EventArgs e)
        {
            var parent = (this.Disposing || this.IsDisposed) ? null : this.Parent;
            if (parent == null || parent.Disposing || parent.IsDisposed) return;
            if (parent is DockPanel) return;
            if (parent is SplitterPanel) return;

            throw new Exception(string.Format("DockSplitControl 只能是 DockPanel 或者 SplitterPanel 的子控件, 而不能是 类型为 '{0}' 的子控件!", parent.GetType().FullName));
        }
        private void DockSplitControlPanelControlAdded(object sender, ControlEventArgs e)
        {
            if (e.Control is DockTabGroup) return;
            if (e.Control is DockSplitControl) return;

            throw new Exception(string.Format("DockSplitControl.Panel 的子控件, 只能是 DockTabGroup 或 DockSplitControl 类型, 而不能是 类型为 '{0}' 的子控件!", e.Control.GetType().FullName));
        }
    }
}
